//
// Created on 2024/8/24.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".


#include "model/ui/node/node_manager.h"
#include "model/ui/node/arkui_base_node.h"
#include <arkui/native_type.h>
namespace NativeArkUI {
    static std::shared_ptr<ArkUIBaseNode> root;
    static ArkUI_NodeContentHandle nodeContent;
/*
 * 设置与ts侧关联的nodeContent
 */
void NodeManager::SetContentHandle(ArkUI_NodeContentHandle handle) { nodeContent = handle; }

/*
 * 设置根组件node
 */
void NodeManager::SetRootNode(const std::shared_ptr<ArkUIBaseNode> &baseNode) {
    root = baseNode;
    // 添加Native组件到NodeContent上用于挂载显示。
    OH_ArkUI_NodeContent_AddNode(nodeContent, root->GetNodeHandle());
}

/*
 * 移除根组件node
 */
void NodeManager::DisposeRootNode() {
    // 从NodeContent上卸载组件并销毁Native组件。
    OH_ArkUI_NodeContent_RemoveNode(nodeContent, root->GetNodeHandle());
    root.reset();
    root = nullptr;
    nodeContent = nullptr;
}

} // namespace NativeArkUI
